﻿using System;
using System.IO;
using EmbeddedMySqlServer;

namespace SimpleServerExample
{
    class Program
    {
        static void Main(string[] args)
        {
            var assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var assemblyDirectory = Path.GetDirectoryName(assemblyLocation);
            if (assemblyDirectory == null)
            {
                Console.WriteLine("Cannot get assembly directory path");
                return;
            }
            var serverPath = Path.Combine(assemblyDirectory, "mysql");

            var mysqlServer = new MySqlServer(serverPath);
            mysqlServer.Start();
            Console.WriteLine("MySQL server started on port {0}", mysqlServer.GetPort());

            const string dbName = "simpletest1";
            mysqlServer.CreateDatabase(dbName);
            Console.WriteLine("Database {0} created", dbName);

            Console.WriteLine("Press any key to stop server\n");
            Console.ReadKey();
            mysqlServer.DropDatabase(dbName);
            Console.WriteLine("Database {0} dropped", dbName);

            mysqlServer.Stop();
            Console.WriteLine("MySQL server stopped");

            Console.WriteLine("Press any key to exit\n");
            Console.ReadKey();
        }
    }
}
